module EasyForm
  module Components
    module Pattern
      def pattern(wrapper_options = nil)
        input_html_options[:pattern] ||= pattern_source
        nil
      end

      private
      def pattern_source
        pattern = options[:pattern]
        if pattern.is_a?(String)
          pattern
        else
          format_validator = find_validator(:format) #找model验证
          return unless format_validator
          with = format_validator.options[:with]
          return unless with
          return with.call(object) if with.respond_to?(:call)#with是proc时，执行proc
          with
        end
      end

    end
  end
end